{
LANG : PASCAL
PROB : agrinet
}

program AGRINET;
const
  fi = 'agrinet.in';
  fo = 'agrinet.out';
  max = 100;
  oo = 1000000000;
var
  a : array[1..max, 1..max] of longint;
  d, trace : array[1..max] of longint;
  free : array[1..max] of boolean;
  n, res : longint;

procedure inp;
var
  i, j : integer;
begin
  read(n);
  for i := 1 to n do
    for j := 1 to n do read(a[i, j]);
end;

procedure init;
var
  i : integer;
begin
  fillchar(free, sizeof(free), true);
  d[1] := 0;
  for i := 2 to n do d[i] := oo;
end;

procedure process;
var
  i, j, u, v : integer;
  min : longint;
begin
  for i := 1 to n-1 do
  begin
    min := oo;
    for j := 1 to n do
      if free[j] and (d[j] < min) then
      begin
        min := d[j];
        u := j;
      end;
    free[u] := false;
    for v := 1 to n do
      if free[v] and (d[v] > a[u, v]) then
      begin
        d[v] := a[u, v];
        trace[v] := u;
      end;
  end;
end;

procedure out;
var
  u, v : integer;
begin
  res := 0;
  for u := 1 to n do
    if trace[u] <> 0 then
    begin
      v := trace[u];
      inc(res, a[u, v]);
    end;
  writeln(res);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  out;
  close(output);
  close(input);
end.